import dbus

class DBusSessionBus():
    
    bus = None

    @classmethod
    def __init__(cls):
        cls.bus = dbus.SessionBus(private=True)
        
    @classmethod
    def sendCommandToGUI(cls, action, args=None):        
        try:
            app = 'org.LinRemote.Server.Gui'
            path = '/org/LinRemote/Server'
            interface = 'org.LinRemote.Server.Gui'
            obj = cls.bus.get_object(app, path)
            DBusInterface = dbus.Interface(obj, interface)
            try:
                response = getattr(DBusInterface, action)(*args)
                return response
            except Exception:
                response = getattr(DBusInterface, action)()
                return response
        except Exception:
            return False
    
    @classmethod
    def sendCommandToDBus(cls, app, path, interface, action, args=None):
        pass